package com.linys.scala.qf.day03

/**
  * 闭包：就是能够读取其他方法（函数）内部的方法（函数）
  */
object ClosureTest {
  def sum(f: Int => Int): (Int, Int) => Int = {
    def sumF(a: Int, b: Int): Int = {
      if (a > b)
        0
      else
        f(a) + sumF(a + 1, b)
    }
    sumF
  }

  def m1(x: Int): Int = {
    def m2(): Int = x + 3
    m2()
  }

  def main(args: Array[String]): Unit = {
   /* def sumInts = sum(x => x + 1)
    val res = sumInts(1, 4)
    println(res)*/

    def m3 = m1(3)
    val res = m3
    println(m3)

  }
}
